import request from '@/utils/request'
import type { Student, PageResult } from '@/types'

/**
 * 分页查询学生
 */
export function getStudentPage(params: any) {
  return request<PageResult<Student>>({
    url: '/student/page',
    method: 'get',
    params
  })
}

/**
 * 获取学生详情
 */
export function getStudentById(id: number) {
  return request<Student>({
    url: `/student/${id}`,
    method: 'get'
  })
}

/**
 * 新增学生
 */
export function addStudent(data: Student) {
  return request<void>({
    url: '/student',
    method: 'post',
    data
  })
}

/**
 * 更新学生
 */
export function updateStudent(data: Student) {
  return request<void>({
    url: '/student',
    method: 'put',
    data
  })
}

/**
 * 删除学生
 */
export function deleteStudent(id: number) {
  return request<void>({
    url: `/student/${id}`,
    method: 'delete'
  })
}

/**
 * 获取当前学生的个人档案（学生端）
 */
export function getMyProfile() {
  return request<any>({
    url: '/student/profile',
    method: 'get'
  })
}

/**
 * 学生更新个人信息（学生端）
 */
export function updateMyProfile(data: {
  avatar?: string
  idPhoto?: string
  phone?: string
  address?: string
}) {
  return request<void>({
    url: '/student/profile/update',
    method: 'put',
    data
  })
}

/**
 * 获取所有学生列表（不分页，用于下拉选择）
 */
export function getAllStudents() {
  return request<Student[]>({
    url: '/student/list',
    method: 'get'
  })
}

/**
 * 学生绑定家长（学生端）
 */
export function bindParents(data: {
  fatherName?: string
  fatherPhone?: string
  motherName?: string
  motherPhone?: string
}) {
  return request<void>({
    url: '/student/bind-parents',
    method: 'post',
    data
  })
}

